<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class StoreVisit extends Model
{
    use HasFactory;
    use PimpableTrait;

    public $searchable = [
        'goods_id',
        'product_type',
        'category_id',
        "type",
        "user_id",
        'count',
        'remark'
    ];
    public $fillable = [
        'goods_id',
        'product_type',
        'category_id',
        "type",
        "user_id",
        'count',
        'remark'
    ];
    public $sortable = [
        'id',
        'goods_id',
        'category_id',
        "user_id",
        'count',
    ];
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 访问的所有用户
     */
    public function user()
    {
        return $this->hasMany(User::class,'user_id','id');
    }

    /**
     * 访问的所属商品
     */
    public function product()
    {
        return $this->belongsTo(Product::class,'product_id','id');
    }

    /**
     * 访问的所属商品分类
     */
    public function category()
    {
        return $this->belongsTo(Category1::class,'category_id','id');
    }

}
